/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
public class Solution {
    public ListNode swapPairs(ListNode head) {
        ListNode dummy = new ListNode(-1, head);
        ListNode first = dummy.next;
        ListNode second;
        while ((first != null) && (second = first.next) != null) {
            int temp = first.val;
            first.val = second.val;
            second.val = temp;
            first = second.next;
        }
        return dummy.next;
    }
}